"""
Prompt generation utilities

This module provides utilities for generating complete prompts by replacing
placeholders with actual content.
"""

def generate_complete_prompt(
    _work_dir: str,
    _project_struct: str, 
    _files_content: str,
    _user_prompt: str
) -> str:
    """
    Generate a complete prompt by replacing placeholders in the template.
    
    Args:
        _work_dir: Working directory path
        _project_struct: Project directory structure
        _files_content: Content of relevant files
        _user_prompt: User's specific request/prompt
        
    Returns:
        str: Complete prompt with all placeholders replaced
        
    Raises:
        ValueError: If any required parameter is empty or None
    """
    # Validate inputs
    if not all((_work_dir, _project_struct, _files_content, _user_prompt)):
        print(_work_dir, _project_struct, _files_content, _user_prompt)
        raise ValueError("All parameters must have non-empty values")

    # Read the template file
    with open("src/prompt/generate_code.txt", "r", encoding="utf-8") as f:
        template = f.read()
    
    # Replace all placeholders
    return template.format(
        _work_dir=_work_dir,
        _project_struct=_project_struct,
        _files_content=_files_content,
        _user_prompt=_user_prompt
    ) 


def generate_ask_prompt(
    _work_dir: str,
    _project_struct: str, 
    _files_content: str
) -> str:
    # Validate inputs
    if not all((_work_dir, _project_struct, _files_content)):
        print(_work_dir, _project_struct, _files_content)
        raise ValueError("All parameters must have non-empty values")

    # Read the template file
    with open("src/prompt/generate_ask.txt", "r", encoding="utf-8") as f:
        template = f.read()
    
    # Replace all placeholders
    return template.format(
        _work_dir=_work_dir,
        _project_struct=_project_struct,
        _files_content=_files_content
    ) 


def generate_summary_prompt(
    _files_content: str
) -> str:
    # Validate inputs
    if not _files_content:
        raise ValueError("All parameters must have non-empty values")

    # Read the template file
    with open("src/prompt/summary.txt", "r", encoding="utf-8") as f:
        template = f.read()
    
    # Replace all placeholders
    return template.format(
        _files_content=_files_content
    ) 

def choose_context_prompt(
    _files_content: str,
    _user_requirement: str
) -> str:
    # Validate inputs
    if not _files_content:
        raise ValueError("All parameters must have non-empty values")
    if not _user_requirement:
        raise ValueError("All parameters must have non-empty values")

    # Read the template file
    with open("src/prompt/choose_context.txt", "r", encoding="utf-8") as f:
        template = f.read()
    
    # Replace all placeholders
    return template.format(
        _files_content=_files_content,
        _user_requirement=_user_requirement
    ) 

def generate_choose_context_prompt(
    _user_requirement: str
) -> str:
    from src.utils.context_loader import ContextLoader
    _files_content = ContextLoader.get_project_summary()
    return choose_context_prompt(
        _files_content=_files_content,
        _user_requirement=_user_requirement
    )
